package com.somsoft.bzfk.db;


import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;


public class Service {
	private DBOpenHelper helper;
	
	public Service(Context context){
		this.helper = new DBOpenHelper(context);
	}
	

	public void save(int level){
		SQLiteDatabase  db = helper.getWritableDatabase();
		try {
			db.beginTransaction();
			db.execSQL("update t_level set level=?",new Object[]{level});
			db.setTransactionSuccessful();  
		} finally {
			db.endTransaction();
			db.close();
		} 
	}
	
	public int getLevel(){
		int level = 0;
		SQLiteDatabase db = helper.getWritableDatabase();
		Cursor cursor =  db.rawQuery("select * from t_level",new String[]{});
		if(cursor.moveToFirst()){
			level = cursor.getInt(cursor.getColumnIndex("level"));
		}
		cursor.close();
		db.close();
		return level;
	}
	
}